package me.zhanshi123.vipsystem.feature;

import cn.nukkit.utils.ConfigSection;
import me.zhanshi123.vipsystem.Main;

public abstract class VipFeature {
    private String name;
    private ConfigSection configSection;

    public VipFeature(String name) {
        this.name = name;
        configSection = Main.getFeatureManager().getConfig().getSection(name);
        if (configSection.size() == 0) {
            configSection = generateDefaultConfig(configSection);
            Main.getFeatureManager().getConfig().set(name, configSection);
            Main.getFeatureManager().getConfig().save();
        }
    }

    public String getName() {
        return name;
    }

    public ConfigSection getConfigSection() {
        return configSection;
    }

    /**
     * 生成默认配置文件
     *
     * @param configSection
     * @return 生成后的配置文件
     */
    public abstract ConfigSection generateDefaultConfig(ConfigSection configSection);

    public void register() {
        Main.getFeatureManager().getFeatureMap().put(name, this);
    }
}
